package com.sanhe.rfmuscle.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;

import com.menu.app.activity.BaseCustomInfoActivity;
import com.menu.app.adapter.BaseCusRecordAdapter;
import com.menu.app.bean.DayRecord;
import com.menu.app.databinding.CusRecordItemBinding;
import com.menu.app.db.CusUsageDao;
import com.menu.app.db.bean.CusUsage;
import com.menu.app.db.bean.Custom;
import com.plata.base.ui.MyRecyclerView;
import com.sanhe.rfmuscle.R;
import com.sanhe.rfmuscle.databinding.RecordContentBinding;

import java.util.HashMap;

public class CusRecordAdapter extends BaseCusRecordAdapter {
    Context context;
    public CusRecordAdapter(Context context, BaseCustomInfoActivity activity, CusUsageDao dao, Custom custom, MyRecyclerView recyclerView, boolean isAdmin) {
        super(activity, dao, custom, recyclerView, isAdmin);
        this.context = context;
    }

    @Override
    protected ItemHolder onCreateViewHolder(CusRecordItemBinding binding, int type, ItemHolder holder) {
        RecordContentBinding tmp = RecordContentBinding.inflate(LayoutInflater.from(binding.getRoot().getContext()), binding.left, false);
        binding.left.addView(tmp.getRoot(), 0);
        holder.contentBinding = tmp;
        return holder;
    }

    @Override
    protected void setInfo(CusUsage data, Object obj) {

        RecordContentBinding binding = (RecordContentBinding) obj;
        binding.mode.setText(getMode(data.info));
        binding.s1Time.setText(data.info.get("time1") + "");
        binding.s1Flu.setText(data.info.get("fluence1") + "");
        binding.s2Time.setText(data.info.get("time2") + "");
        binding.s2Flu.setText(data.info.get("fluence2") + "");
        binding.time.setText(data.info.get("time") + "");
        binding.point.setText(data.point + "");

    }

    @Override
    protected void bindHolder(RecyclerView.ViewHolder holder, int position) {
        super.bindHolder(holder, position);
        ((ItemHolder) holder).binding.more.setVisibility(View.GONE);
    }

    public String getMode(HashMap<String, String> map) {
        try {
            String s = map.get("mode");
            int type = Integer.valueOf(s);
            if (type == 1) {
                return context.getResources().getString(R.string.sport);
            } else if (type == 2) {
                return context.getResources().getString(R.string.gentle);
            } else if (type == 3) {
                return context.getResources().getString(R.string.pro);
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return "--";

    }


    @Override
    public int getItemViewType(int position) {
        CusUsage item = list.get(position).record.get(0);
        if ("0".equals(item.part)) {
            return 0;
        }
        return 1;
    }

    @Override
    protected boolean deletePic(DayRecord day) {
        return false;
    }
}
